<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/main.css">
<style>
    .tree li {
        list-style-type: none;
        cursor:pointer;
    }
    .tree-closed {
        height : 40px;
    }
    .tree-expanded {
        height : auto;
    }
</style>
</head>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <div class="panel panel-default">
        <div class="panel-body">
            <hr style="clear:both;">
            <div class="table-responsive">
                <button type="button" id="batchRemoveBtn" class="btn btn-danger" style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除</button>
                <table class="table  table-bordered">
                    <thead>
                    <tr >
                        <th width="30">#</th>
                        <th width="30"><input id="summaryBox" type="checkbox"></th>
                        <th>账号</th>
                        <th>名称</th>
                        <th>邮箱地址</th>

                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="admin,myStatus : ${#request.getAttribute('PAGE-INFO').list}">
                        <td th:text="${myStatus.count}"></td>
                        <td><input type="checkbox" th:adminId="${admin.id}"class="itemBox" ></td>
                        <td th:text="${admin.loginacct}"></td>
                        <td th:text="${admin.username}"></td>
                        <td th:text="${admin.email}"></td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr >
                        <td colspan="6" align="center">
                            <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
<script src="/jquery/jquery-2.1.1.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/script/docs.min.js"></script>
<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        // 对分页导航条显示进行初始化
        //  initPagination();

        //批量删除
        $("#batchRemoveBtn").click(function () {
            // 创建数组对象：存储adminId
            var adminIdArray = new Array();
            $(".itemBox:checked").each(function () {
                var adminId = $(this).attr("adminId");
                adminIdArray.push(adminId);
            });
            // 创建数组对象：存储loginAcct
            var loginAcctArray = new Array();
            $(".itemBox:checked").each(function () {
                var loginAcct = $(this).parent("td").next().text();
                loginAcctArray.push(loginAcct);
            });
            if (adminIdArray.length == 0) {
                alert("请勾选您要删除的记录！");
                return;
            }
            var confirmResult = confirm("您真的要删除" + loginAcctArray + "信息吗？操作不可逆，请谨慎决定！");
            if (confirmResult == false) {
                return;
            }
            var requestBody = JSON.stringify(adminIdArray);
            $.ajax({
                url: "/admin/batch/remove",
                type: "post",
                data: requestBody,
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function (response) {
                    var result = response.result;
                    if (result == "SUCCESS") {
                        // 跳转页面
                        var pageNum = [[${#request.getAttribute('PAGE-INFO').pageNum}]];
                        var keyword = $('[name="keyword"]').val();
                        window.location.href = "/admin/query/for/search?pageNum=" + pageNum + "&keyword=" + keyword;
                    } else {
                        alert(response.message);
                        return;
                    }
                }
            });
        });
            //全选删除
        $("#summaryBox").click(function () {
            // 获取当前#summaryBox的勾选状态
            // this代表当前多选框对象（DOM对象）
            // checked属性为true时表示被勾选，为false时表示没有被勾选
            // 使用checkStatus设置.itemBox的状态
            $(".itemBox").prop("checked", this.checked);
        });
    });
</script>